package org.hot100_3;

public class leetcode152 {
    public static int maxProduct(int[] nums) {

        int n = nums.length;
        if (n == 1) {
            return nums[0];
        }

        int[] maxDp = new int[n];
        int[] minDp = new int[n];

        maxDp[0] = nums[0];
        minDp[0] = nums[0];

        int max = nums[0];

        for (int i = 1; i < n; i++) {
            maxDp[i] = Math.max(nums[i], Math.max(nums[i] * maxDp[i - 1], nums[i] * minDp[i - 1]));
            minDp[i] = Math.min(nums[i], Math.min(nums[i] * maxDp[i - 1], nums[i] * minDp[i - 1]));

            max = Math.max(max, maxDp[i]);
        }
        return max;
    }

    public static void main(String[] args) {
        int[] array = {0, 2};
        int i = maxProduct(array);
        System.out.println(i);
    }
}
